/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package asa;

/**
 *
 * @author scriptoff
 */
public class ASAInstIfElse extends ASAInst implements NeedBlocInterface {

    private final ASAExpr expr;
    private final ASAInst bloc_if;
    private final ASAInst bloc_else;

    public ASAInstIfElse(ASAExpr expr, ASAInst bloc_if, ASAInst bloc_else) {
        this.expr = expr;
        this.bloc_if = bloc_if;
        this.bloc_else = bloc_else;
    }

    @Override
    public void evalue() {
        if (expr.evalue() != 0) {
            bloc_if.evalue();
        } else {
            if (bloc_else != null) {
                bloc_else.evalue();
            }
        }
    }

    @Override
    public ASAExpr getExpr1() {
        return expr;
    }

    @Override
    public ASAExpr getExpr2() {
        return null;
    }

    @Override
    public String getLabelExplorateur() {
        return "IF-ELSE";
    }

    @Override
    public void setBl(ASABloc bl) {
        expr.setBl(bl);        
        if (bloc_if.getExpr1() != null) {
            try {
                NeedBlocInterface nBI = (NeedBlocInterface) bloc_if.getExpr1();
                nBI.setBl(bl);
            } catch (ClassCastException ex) {
            }
        }
        if (bloc_if.getExpr2() != null) {
            try {
                NeedBlocInterface nBI = (NeedBlocInterface) bloc_if.getExpr2();
                nBI.setBl(bl);
            } catch (ClassCastException ex) {
            }
        }
        if (bloc_else != null) {
            if (bloc_else.getExpr1() != null) {
                try {
                    NeedBlocInterface nBI = (NeedBlocInterface) bloc_else.getExpr1();
                    nBI.setBl(bl);
                } catch (ClassCastException ex) {
                }
            }
            if (bloc_else.getExpr2() != null) {
                try {
                    NeedBlocInterface nBI = (NeedBlocInterface) bloc_else.getExpr2();
                    nBI.setBl(bl);
                } catch (ClassCastException ex) {
                }
            }
        }

    }
}
